var express = require('express');
var router = express.Router();
var { query } = require('../../utils/db.js')
console.log(query)

//栏目列表页
router.get('/list',(req,res)=>{

    var sql = 'select * from category'
    query(sql,function(data){
        res.render('admin/category/list',{categories:data})
    })
})

router.post('/add',(req,res)=>{
    console.log(req.body)
    var category = req.body
    var sql = `insert into category (cname,active) values ("${category.cname}",${category.active})`
    query(sql,function(data){
        res.redirect('/admin/category/list')
    })
})


module.exports = router;